import requests


def get_qy_access_token(app_id, secret_key):
    url = f"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={app_id}&secret={secret_key}"
    response = requests.get(url)
    data = response.json()
    token = data["access_token"]
    print(data)
    return token


def get_address():
    ACCESS_TOKEN = get_qy_access_token(app_id, secret_key)
    url = f"https://api.weixin.qq.com/cgi-bin/get_api_domain_ip?access_token={ACCESS_TOKEN}"
    response = requests.get(url)
    print(response.text)


def ping_address():
    ACCESS_TOKEN = get_qy_access_token(app_id, secret_key)
    url = f"https://api.weixin.qq.com/cgi-bin/callback/check?access_token={ACCESS_TOKEN}"
    data = {
        "action": "all",
        "check_operator": "DEFAULT"
    }
    headers = {
        "Content-Type": "application/json"
    }
    respones = requests.post(url, headers=headers, json=data)
    print(respones.text)


# 替换为你的 CorpID 和 Secret
app_id = "wx0affea6ee2d00150"
secret_key = "a8aa4150a8f37f607db7f0537403bcd1"
access_token = get_qy_access_token(app_id, secret_key)
print("Access Token:", access_token)
if __name__ == '__main__':
    # get_address()
    ping_address()
